﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using System.Data;

namespace ShiTai_WeightService
{

    public partial class SqlBase : DbContext
    {
        /// <summary>
        /// 连接字符串
        /// </summary>
        private string _ConnString { get; set; }

        /// <summary>
        /// 数据库类型 不同的数据库之间sql也会存在差异
        /// </summary>
        public DBType DBType { get; set; }

        public SqlBase(string connstring, DBType DBType) : base()
        {

            this._ConnString = connstring;
            this.DBType = DBType;
        }

        /// <summary>
		/// 创建数据库连接
		/// </summary>
		/// <param name="builder"></param>
		protected override void OnConfiguring(DbContextOptionsBuilder builder)
        {
            if (this.DBType == DBType.SqlServer)
            {
                /* 通过构造函数传入连接字符串 */
                builder.UseSqlServer(this._ConnString);
            }
        }

    }


    public enum DBType
    {
        SqlServer = 0,
        MySql = 1,
        Oracle = 2,
        MongoDB = 3
    }
}
